﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapICC_PRNDEF(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void MapICC_MENUDEF(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_MENUDEF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryICC_MENUDEF(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapICC_MENUDEF(ref dwLocal, dwData);

            if (!flgExist)
            {
                dwLocal["ROWNID"] = GetSeq();
                InsertICC_MENUDEF(dwLocal, ITXDBVERSION);
            }
            UpdateICC_MENUDEF(dwLocal);

        }
        public void InsertICC_MENUDEF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "50.24":
                    or1.CommandText = "INSERT INTO ICC_MENUDEF(MANDANT, ROWNID, COMPANY, USERID, PROCESS, MENUITEM, MENUID, FATHER, HEADER, TAG, ICON, LARGEICON)"
                        + " VALUES (:MANDANT, :ROWNID, :COMPANY,:USERID,:PROCESS, :MENUITEM, :MENUID, :FATHER, :HEADER, :TAG, :ICON, :LARGEICON)";
                    break;
                default:
                    break;
            }
            or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
            or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
            or1.Parameters.Add("COMPANY", OracleType.NVarChar).Value = dwData["COMPANY"].ToString();
            or1.Parameters.Add("USERID", OracleType.NVarChar).Value = dwData["USERID"].ToString();
            or1.Parameters.Add("PROCESS", OracleType.NVarChar).Value = dwData["PROCESS"].ToString();
            or1.Parameters.Add("MENUITEM", OracleType.NVarChar).Value = dwData["MENUITEM"].ToString();
            or1.Parameters.Add("MENUID", OracleType.NVarChar).Value = dwData["MENUID"].ToString();
            or1.Parameters.Add("FATHER", OracleType.NVarChar).Value = dwData["FATHER"].ToString();
            or1.Parameters.Add("HEADER", OracleType.NVarChar).Value = dwData["HEADER"].ToString();
            or1.Parameters.Add("TAG", OracleType.NVarChar).Value = dwData["TAG"].ToString();
            or1.Parameters.Add("ICON", OracleType.NVarChar).Value = dwData["ICON"].ToString();
            or1.Parameters.Add("LARGEICON", OracleType.NVarChar).Value = dwData["LARGEICON"].ToString();
            Connect2Proxy(or1);
        }
        public void DeleteICC_MENUDEF(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_MENUDEF  WHERE PROCESS='HIDDEN'";
                    break;
                default:
                    break;
            }

            Connect2Proxy(or1);
        }
        public void DeleteICC_MENUDEF(string client, string company, string userid)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM ICC_MENUDEF"
         + " WHERE MANDANT=:MANDANT AND COMPANY=:COMPANY AND USERID=:USERID";
            or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = client;
            or1.Parameters.Add("COMPANY", OracleType.NVarChar).Value = company;
            or1.Parameters.Add("USERID", OracleType.NVarChar).Value = userid;
            Connect2Proxy(or1);
        }
        public DataSet QueryICC_MENUDEF(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_MENUDEF WHERE MANDANT=:MANDANT  AND ROWNID=:ROWNID"; ;
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM ICC_MENUDEF WHERE MANDANT=:MANDANT AND COMPANY=:COMPANY AND USERID=:USERID"; ;
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("COMPANY", OracleType.NVarChar).Value = dwData["COMPANY"].ToString();
                    or1.Parameters.Add("USERID", OracleType.NVarChar).Value = dwData["USERID"].ToString();
                    break;
                case 3:
                    or1.CommandText = "SELECT * FROM ICC_MENUDEF WHERE MANDANT=:MANDANT AND COMPANY=:COMPANY"; ;
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("COMPANY", OracleType.NVarChar).Value = dwData["COMPANY"].ToString();
                    break;
                case 9999:
                    or1.CommandText = "SELECT * FROM ICC_MENUDEF WHERE MANDANT=:MANDANT AND COMPANY=:COMPANY"; ;
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("COMPANY", OracleType.NVarChar).Value = dwData["COMPANY"].ToString();
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_MENUDEF";
            Return = Result;
            return Return;
        }
        public void UpdateICC_MENUDEF(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();

            #region====Command====
            or1.CommandText = "UPDATE ICC_MENUDEF SET "
+ "COMPANY=:COMPANY,"
+ "USERID=:USERID,"
+ "PROCESS=:PROCESS,"
+ "MENUITEM=:MENUITEM,"
+ "MENUID=:MENUID,"
+ "FATHER=:FATHER,"
+ "HEADER=:HEADER,"
+ "TAG=:TAG,"
+ "ICON=:ICON,"
+ "LARGEICON=:LARGEICON,"
+ "JOB=:JOB,"
+ "TIMER=:TIMER,"
+ "SCHEDULETYPE=:SCHEDULETYPE,"
+ "FREQUENCY=:FREQUENCY,"
+ "TIME=:TIME "
                + " WHERE  "
                + "  MANDANT=:MANDANT AND ROWNID=:ROWNID";
            #endregion

            #region====Parameters====
            or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
            or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
            or1.Parameters.Add("COMPANY", OracleType.NVarChar).Value = dwData["COMPANY"].ToString();
            or1.Parameters.Add("USERID", OracleType.NVarChar).Value = dwData["USERID"].ToString();
            or1.Parameters.Add("PROCESS", OracleType.NVarChar).Value = dwData["PROCESS"].ToString();
            or1.Parameters.Add("MENUITEM", OracleType.NVarChar).Value = dwData["MENUITEM"].ToString();
            or1.Parameters.Add("MENUID", OracleType.NVarChar).Value = dwData["MENUID"].ToString();
            or1.Parameters.Add("FATHER", OracleType.NVarChar).Value = dwData["FATHER"].ToString();
            or1.Parameters.Add("HEADER", OracleType.NVarChar).Value = dwData["HEADER"].ToString();
            or1.Parameters.Add("TAG", OracleType.NVarChar).Value = dwData["TAG"].ToString();
            or1.Parameters.Add("ICON", OracleType.NVarChar).Value = dwData["ICON"].ToString();
            or1.Parameters.Add("LARGEICON", OracleType.NVarChar).Value = dwData["LARGEICON"].ToString();
            or1.Parameters.Add("JOB", OracleType.NVarChar).Value = dwData["JOB"].ToString();
            or1.Parameters.Add("TIMER", OracleType.NVarChar).Value = dwData["TIMER"].ToString();
            or1.Parameters.Add("SCHEDULETYPE", OracleType.NVarChar).Value = dwData["SCHEDULETYPE"].ToString();
            or1.Parameters.Add("FREQUENCY", OracleType.NVarChar).Value = dwData["FREQUENCY"].ToString();
            or1.Parameters.Add("TIME", OracleType.NVarChar).Value = dwData["TIME"].ToString();
            #endregion

            Connect2Proxy(or1);
        }
    }
}
